import React from 'react'
import {useEffect,useState} from "react"
import axios from "axios"
import {useNavigate} from "react-router-dom"
function Movie() {
  let [arr,setArr] = useState([])
  let navigate = useNavigate()
  useEffect(()=>{
      axios.get("/list1").then(res=>{
        setArr(res.data)
      })
  },[])
  let goDetail = (item)=>{
        navigate("/detail",{
          state:{
            detailinfo:item
          }
        })
  }
  return (
    <div>
      {
        arr && arr.length ? arr.map((item,index)=>{
            return <div key={index} onClick={()=>goDetail(item.dettail)}>
                 <img src={item.img} alt="" />
                 <h4>{item.title}</h4>
            </div>
        }):"暂无数据"
      }
    </div>
  )
}

export default Movie